module CloudFoundry
  class Client
    # CloudFoundry API Applications methods.
    module Slas


      def create_sla_template(name, manifest = {})
        require_login
        raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
        raise CloudFoundry::Client::Exception::BadParams, "Manifest cannot be blank" if manifest.nil? || manifest.empty?
        sla = manifest.dup
        sla[:name] = name


        post(CloudFoundry::Client::SLATS_PATH, sla)

        true
      end



      def delete_sla_template(name)
        require_login
        raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
        delete("#{CloudFoundry::Client::SLATS_PATH}/#{name}", :raw => true)
        true
      end

      def list_sla_templates()
        require_login
        get(CloudFoundry::Client::SLATS_PATH)
      end

      def sla_template_info(name)
        require_login
        raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
        get("#{CloudFoundry::Client::SLATS_PATH}/#{name}")
      end



      def create_sla_instance(name, manifest = {})
        require_login
        raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
        raise CloudFoundry::Client::Exception::BadParams, "Manifest cannot be blank" if manifest.nil? || manifest.empty?
        sla = manifest.dup
        sla[:name] = name


        post(CloudFoundry::Client::SLAIS_PATH, sla)

        true
      end



      def delete_sla_instance(name)
        require_login
        raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
        delete("#{CloudFoundry::Client::SLAIS_PATH}/#{name}", :raw => true)
        true
      end

      def list_sla_instances()
        require_login
        get(CloudFoundry::Client::SLAIS_PATH)
      end

      def sla_instance_info(name)
        require_login
        raise CloudFoundry::Client::Exception::BadParams, "Name cannot be blank" if name.nil? || name.empty?
        get("#{CloudFoundry::Client::SLAIS_PATH}/#{name}")
      end


    end
  end
end